﻿<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">设备编号</label>
        <div class="layui-input-inline">
            <select id="EquipmentID" name="EquipmentID" lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">绑定园区</label>
        <div class="layui-input-inline">
            <select id="ParkID" name="ParkID" lay-filter="ParkID" lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">绑定仓库</label>
        <div class="layui-input-inline">
            <select id="StorehouseID" name="StorehouseID" lay-filter="StorehouseID">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">绑定库位</label>
        <div class="layui-input-inline">
            <select id="LocationID" name="LocationID" lay-filter="LocationID">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn" lay-submit lay-filter="save">保存</button>
        <button class="layui-btn" id="cancel">取消</button>
    </div>
</form>
<script type="text/javascript">
    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        $.ajax({
            url: '/Monitor/Equipment/SelectList',
            data: { code: 0 },
            success: function (res) {
                if (res.count > 0) {
                    $(res.data).each(function (index, item) {
                        $("#EquipmentID").append("<option value='" + item.value + "'>" + item.text + "</option>");
                    });
                    form.render("select");
                }
            }
        });
        $.ajax({
            url: '/Resource/Park/SelectList',
            success: function (res) {
                if (res.count > 0) {
                    $(res.data).each(function (index, item) {
                        $("#ParkID").append("<option value='" + item.value + "'>" + item.text + "</option>");
                    });
                    form.render("select");
                }
            }
        });
        form.on('select(ParkID)', function (obj) {
            $("#StorehouseID").empty();
            $("#StorehouseID").append("<option value=''>请选择或搜索</option>");
            $.ajax({
                url: '/Resource/Storehouse/SelectList',
                data: { parkID: obj.value },
                success: function (res) {
                    if (res.count > 0) {
                        $(res.data).each(function (index, item) {
                            $("#StorehouseID").append("<option value='" + item.value + "'>" + item.text + "</option>");
                        });
                        form.render("select");
                    }
                }
            });
        });
        form.on('select(StorehouseID)', function (obj) {
            $("#LocationID").empty();
            $("#LocationID").append("<option value=''>请选择或搜索</option>");
            $.ajax({
                url: '/Resource/Location/SelectList',
                data: { storehouseID: obj.value },
                success: function (res) {
                    if (res.count > 0) {
                        $(res.data).each(function (index, item) {
                            $("#LocationID").append("<option value='" + item.value + "'>" + item.text + "</option>");
                        });
                        form.render("select");
                    }
                }
            });

        });
        form.on("submit(save)", function (formdata) {
            $.ajax({
                url: 'Add',
                data: formdata.field,
                success: function (res) {
                    layer.alert(res.msg, function (index) {
                        layer.close(index);
                        if (res.count > 0) {
                            parent.layer.closeAll();
                        }
                    })
                }
            });
            return false;
        })
        $("#cancel").click(function () {
            parent.layer.closeAll();
        })
    })
</script>